home *** CD-ROM | disk | FTP | other *** search
/ Quick PC 61 / Quick PC 61.iso / I386 / IISVDIR.VB_ / iisvdir.vbs
Encoding:
Text File  |  2003-02-21  |  33.8 KB  |  930 lines

  1. '
  2. ' Copyright (c) Microsoft Corporation.  All rights reserved.
  3. '
  4. ' VBScript Source File 
  5. '
  6. ' Script Name: IIsVDir.vbs
  7. '
  8.  
  9. Option Explicit
  10. On Error Resume Next
  11.  
  12. ' Error codes
  13. Const ERR_OK              = 0
  14. Const ERR_GENERAL_FAILURE = 1
  15.  
  16. '''''''''''''''''''''
  17. ' Messages
  18. Const L_WebDir_Message           = "Web directory %1 has been DELETED"
  19. Const L_InvalidPath_ErrorMessage = "Invalid site path."
  20.  
  21. Const L_VPath_Message        = "Virtual Path"
  22. Const L_Root_Message         = "ROOT"
  23. Const L_MetabasePath_Message = "Metabase Path"
  24. Const L_AliasName_Text       = "Alias"
  25. Const L_Path_Text            = "Physical Root"
  26.  
  27. Const L_Error_ErrorMessage                = "Error &H%1: %2"
  28. Const L_AppRecursiveDel_ErrorMessage      = "Could not recursively delete application from web directory."
  29. Const L_VDirDel_ErrorMessage              = "Could not delete web directory."
  30. Const L_CannotCreateDir_ErrorMessage      = "Could not create root directory."
  31. Const L_DirFormat_ErrorMessage            = "Root directory format unknown. Please use the"
  32. Const L_DirFormat2_ErrorMessage           = "'<drive>:\<path>' format."
  33. Const L_AppCreate_ErrorMessage            = "Error trying to create pooled-proc application on new web"
  34. Const L_AppCreate2_ErrorMessage           = "directory."
  35. Const L_OperationRequired_ErrorMessage    = "Please specify an operation before the arguments."
  36. Const L_NotEnoughParam_ErrorMessage       = "Not enough parameters."
  37. Const L_Query_ErrorMessage                = "Error occurred while querying WMI provider."
  38. Const L_VDirExists1_ErrorMessage          = "The virtual directory %1 does not exist."
  39. Const L_VDirExists2_ErrorMessage          = "The virtual directory %1 already exists."
  40. Const L_VDirDoesntExist_ErrorMessage      = "Either the path specified is not an IIsVirtualDir object or"
  41. Const L_VDirDoesntExist2_ErrorMessage     = "the path does not exist (%1)"
  42. Const L_OnlyOneOper_ErrorMessage          = "Please specify only one operation at a time."
  43. Const L_ScriptHelper_ErrorMessage         = "Could not create an instance of the IIsScriptHelper object."
  44. Const L_CmdLib_ErrorMessage               = "Could not create an instance of the CmdLib object."
  45. Const L_ChkCmdLibReg_ErrorMessage         = "Please register the Microsoft.CmdLib component."
  46. Const L_ChkScpHelperReg_ErrorMessage      = "Please register the Microsoft.IIsScriptHelper component."
  47. Const L_VDirsNotFound_ErrorMessage        = "No virtual sub-directories available."
  48. Const L_SiteNotFound_ErrorMessage         = "Could not find website %1"
  49. Const L_PassWithoutUser_ErrorMessage      = "Please specify /u switch before using /p."
  50. Const L_WMIConnect_ErrorMessage           = "Could not connect to WMI provider."
  51. Const L_MapDrive_ErrorMessage             = "Could not map network drive."
  52. Const L_GetSetting_ErrorMessage           = "Unable to get Setting class from IIS namespace."
  53. Const L_CannotDelRoot_ErrorMessage        = "Cannot delete the ROOT virtual directory. Please specify"
  54. Const L_CannotDelRoot2_ErrorMessage       = "another one."
  55. Const L_WrongVDirPath_ErrorMessage        = "Parent virtual directory points to an unexistant file"
  56. Const L_WrongVDirPath2_ErrorMessage       = "system path."
  57. Const L_CannotBuildNameSpace_ErrorMessage = "Could not build metabase namespace for the new virtual"
  58. Const L_CannotBuildNameSpace2_ErrorMessage = "directory."
  59. Const L_KeyIsntVDir_ErrorMessage          = "Specified metabase path is not a virtual directory."
  60. Const L_CannotGetVDir_ErrorMessage        = "Either the path specified does not exist or it is not a"
  61. Const L_CannotGetVDir2_ErrorMessage       = "virtual directory.  Please make sure the path specified is"
  62. Const L_CannotGetVDir3_ErrorMessage       = "valid."
  63. Const L_InvalidAlias_ErrorMessage         = "Alias contains invalid character(s)."
  64. Const L_NotEnoughParams_ErrorMessage      = "Not enough parameters."
  65. Const L_InvalidSwitch_ErrorMessage        = "Invalid switch: %1"
  66. Const L_Admin_ErrorMessage                = "You cannot run this command because you are not an"
  67. Const L_Admin2_ErrorMessage               = "administrator on the server you are trying to configure."
  68.  
  69. '''''''''''''''''''''
  70. ' Help
  71.  
  72. ' General help messages
  73. Const L_SeeHelp_Message          = "Type IIsVDir /? for help."
  74. Const L_SeeCreateHelp_Message    = "Type IIsVDir /create /? for help."
  75. Const L_SeeDeleteHelp_Message    = "Type IIsVDir /delete /? for help."
  76. Const L_SeeQueryHelp_Message     = "Type IIsVDir /query /? for help."
  77.  
  78. Const L_Help_HELP_General01_Text  = "Description: Create, delete, or query a web directory"
  79. Const L_Help_HELP_General02_Text  = "Syntax: IIsVDir [/s <server> [/u <username> [/p <password>]]]"
  80. Const L_Help_HELP_General03_Text  = "        /<operation> [arguments]"
  81. Const L_Help_HELP_General04_Text  = "Parameters:"
  82. Const L_Help_HELP_General06_Text  = "Value                   Description"
  83. Const L_Help_HELP_General07_Text  = "/s <server>             Connect to machine <server>"
  84. Const L_Help_HELP_General07a_Text = "                        [Default: this system]"
  85. Const L_Help_HELP_General08_Text  = "/u <username>           Connect as <domain>\<username> or"
  86. Const L_Help_HELP_General09_Text  = "                        <username> [Default: current user]"
  87. Const L_Help_HELP_General10_Text  = "/p <password>           Password for the <username> user"
  88. Const L_Help_HELP_General11_Text  = "<operation>             /create  Creates a web virtual directory"
  89. Const L_Help_HELP_General12_Text  = "                                 on a specified web site."
  90. Const L_Help_HELP_General13_Text  = "                        /delete  Deletes a web virtual directory"
  91. Const L_Help_HELP_General14_Text  = "                                 from a specified web site."
  92. Const L_Help_HELP_General15_Text  = "                        /query   Lists all virtual directories"
  93. Const L_Help_HELP_General16_Text  = "                                 under the specified path."
  94. Const L_Help_HELP_General17_Text  = "For detailed usage:"
  95. Const L_Help_HELP_General18_Text  = "IIsVDir /create /?"
  96. Const L_Help_HELP_General19_Text  = "IIsVDir /delete /?"
  97. Const L_Help_HELP_General20_Text  = "IIsVDir /query /?"
  98.  
  99. ' Common to all status change commands
  100. Const L_Help_HELP_Common03_Text   = "Parameters:"
  101. Const L_Help_HELP_Common09_Text   = "<website>               Use either the site name or metabase"
  102. Const L_Help_HELP_Common09p1_Text = "                        path to specify the site. (""Default"
  103. Const L_Help_HELP_Common09p2_Text = "                        Web Site"" or w3svc/1)"
  104. Const L_Help_HELP_Common10_Text   = "<path>                  Virtual path for the new virtual"
  105. Const L_Help_HELP_Common10p1_Text = "                        directory's parent. This virtual"
  106. Const L_Help_HELP_Common10p2_Text = "                        path must already exist."
  107. Const L_Help_HELP_Common11_Text   = "Examples:"
  108.  
  109. ' Delete help messages
  110. Const L_Help_HELP_Delete01_Text   = "Description: Deletes a web virtual directory from a"
  111. Const L_Help_HELP_Delete01p1_Text = "             specified web site."
  112. Const L_Help_HELP_Delete02_Text   = "Syntax: IIsVDir [/s <server> [/u <username> [/p <password>]]]"
  113. Const L_Help_HELP_Delete02p1_Text = "        /delete <website>[/path]<alias>"
  114. Const L_Help_HELP_Delete11_Text   = "IIsVDir /delete ""My Site""/Mydir"
  115. Const L_Help_HELP_Delete12_Text   = "IIsVDir /delete w3svc/1/ROOT/Users/Public/Mydir"
  116. Const L_Help_HELP_Delete13_Text   = "IIsVDir /s Server1 /u Administrator /p p@ssWOrd /delete ""My Site""/Mydir"
  117.  
  118. ' Query help messages
  119. Const L_Help_HELP_Query01_Text   = "Description: Lists all virtual directories under a given"
  120. Const L_Help_HELP_Query01p1_Text = "             path."
  121. Const L_Help_HELP_Query02_Text   = "Syntax: IIsVDir [/s <server> [/u <username> [/p <password>]]]"
  122. Const L_Help_HELP_Query02p1_Text = "        /query <website>[/path]"
  123. Const L_Help_HELP_Query11_Text   = "IIsVDir /query ""My Site"""
  124. Const L_Help_HELP_Query12_Text   = "IIsVDir /query w3svc/1/ROOT"
  125. Const L_Help_HELP_Query13_Text   = "IIsVDir /query ""My Site""/Users/Public"
  126. Const L_Help_HELP_Query14_Text   = "IIsVDir /s Server1 /u Administrator /p p@ssWOrd /query ""My Site""/Users"
  127.  
  128. ' Create help messages
  129. Const L_Help_HELP_Create01_Text   = "Description: Creates a web virtual directory on a specified"
  130. Const L_Help_HELP_Create01p1_Text = "             web site."
  131. Const L_Help_HELP_Create02_Text   = "Syntax: IIsVDir [/s <server> [/u <username> [/p <password>]]] /create"
  132. Const L_Help_HELP_Create02p1_Text = "        <website>[/path] <alias> <root>"
  133. Const L_Help_HELP_Create11_Text   = "<alias>                 The name of the virtual directory"
  134. Const L_Help_HELP_Create12_Text   = "<root>                  Physical path of the virtual"
  135. Const L_Help_HELP_Create12p1_Text = "                        directory. If the physical path does"
  136. Const L_Help_HELP_Create12p2_Text = "                        not exist, it will be created."
  137. Const L_Help_HELP_Create15_Text   = "IIsVDir /create ""My Site"" Mydir c:\mydir"
  138. Const L_Help_HELP_Create16_Text   = "IIsVDir /create w3svc/1/ROOT MyDir c:\mydir"
  139. Const L_Help_HELP_Create17_Text   = "IIsVDir /create ""My Site""/Users/Public Mydir c:\mydir"
  140. Const L_Help_HELP_Create18_Text   = "IIsVDir /s Server1 /u Administrator /p p@assWOrd /create ""My Site"" Mydir"
  141. Const L_Help_HELP_Create19_Text   = "        c:\mydir"
  142.  
  143. ''''''''''''''''''''''''
  144. ' Operation codes
  145. Const OPER_DELETE = 1
  146. Const OPER_CREATE = 2
  147. Const OPER_QUERY  = 3
  148.  
  149. '
  150. ' Main block
  151. '
  152. Dim oScriptHelper, oCmdLib
  153. Dim strServer, strUser, strPassword, strSite
  154. Dim strPath, strVPath, strAlias, strRoot
  155. Dim intOperation, intResult
  156. Dim aArgs, arg
  157. Dim strCmdLineOptions
  158. Dim oError
  159.  
  160. ' Default values
  161. strServer = "."
  162. strUser = ""
  163. strPassword = ""
  164. intOperation = 0
  165. strSite = ""
  166. strPath = ""
  167.  
  168. ' Instantiate the CmdLib for output string formatting
  169. Set oCmdLib = CreateObject("Microsoft.CmdLib")
  170. If Err.Number <> 0 Then
  171.     WScript.Echo L_CmdLib_ErrorMessage
  172.     WScript.Echo L_ChkCmdLibReg_ErrorMessage    
  173.     WScript.Quit(ERR_GENERAL_FAILURE)
  174. End If
  175. Set oCmdLib.ScriptingHost = WScript.Application
  176.  
  177. ' Instantiate script helper object
  178. Set oScriptHelper = CreateObject("Microsoft.IIsScriptHelper")
  179. If Err.Number <> 0 Then
  180.     WScript.Echo L_ScriptHelper_ErrorMessage
  181.     WScript.Echo L_ChkScpHelperReg_ErrorMessage    
  182.     WScript.Quit(ERR_GENERAL_FAILURE)
  183. End If
  184.  
  185. Set oScriptHelper.ScriptHost = WScript
  186.  
  187. ' Check if we are being run with cscript.exe instead of wscript.exe
  188. oScriptHelper.CheckScriptEngine
  189.  
  190. ' Minimum number of parameters must exist
  191. If WScript.Arguments.Count < 1 Then
  192.     WScript.Echo L_NotEnoughParam_ErrorMessage
  193.     WScript.Echo L_SeeHelp_Message
  194.     WScript.Quit(ERR_GENERAL_FAILURE)
  195. End If
  196.  
  197. strCmdLineOptions = "[server:s:1;user:u:1;password:p:1];delete:d:1;create:c:3;query:q:1"
  198. Set oError = oScriptHelper.ParseCmdLineOptions(strCmdLineOptions)
  199.  
  200. If Not oError Is Nothing Then
  201.     If oError.ErrorCode = oScriptHelper.ERROR_NOT_ENOUGH_ARGS Then
  202.         ' Not enough arguments for a specified switch
  203.         WScript.Echo L_NotEnoughParams_ErrorMessage
  204.         Select Case LCase(oError.SwitchName)
  205.             Case "create"
  206.                 WScript.Echo L_SeeCreateHelp_Message
  207.             
  208.             Case "delete"
  209.                 WScript.Echo L_SeeDeleteHelp_Message
  210.  
  211.             Case "query"
  212.                 WScript.Echo L_SeeQueryHelp_Message
  213.  
  214.             Case Else
  215.                    WScript.Echo L_SeeHelp_Message
  216.         End Select
  217.     Else
  218.         ' Invalid switch
  219.         oCmdLib.vbPrintf L_InvalidSwitch_ErrorMessage, Array(oError.SwitchName)
  220.           WScript.Echo L_SeeHelp_Message
  221.     End If
  222.         
  223.         WScript.Quit(ERR_GENERAL_FAILURE)
  224. End If
  225.  
  226. If oScriptHelper.GlobalHelpRequested Then
  227.     DisplayHelpMessage
  228.     WScript.Quit(ERR_OK)
  229. End If
  230.     
  231. For Each arg In oScriptHelper.Switches
  232.     Select Case arg
  233.         Case "server"
  234.             ' Server information
  235.             strServer = oScriptHelper.GetSwitch(arg)
  236.  
  237.         Case "user"
  238.             ' User information
  239.             strUser = oScriptHelper.GetSwitch(arg)
  240.  
  241.         Case "password"
  242.             ' Password information
  243.             strPassword = oScriptHelper.GetSwitch(arg)
  244.         
  245.         Case "create"
  246.             If (intOperation <> 0) Then
  247.                 WScript.Echo L_OnlyOneOper_ErrorMessage
  248.                 WScript.Echo L_SeeHelp_Message
  249.                 WScript.Quit(ERR_GENERAL_FAILURE)
  250.             End If
  251.  
  252.             intOperation = OPER_CREATE
  253.  
  254.                If oScriptHelper.IsHelpRequested(arg) Then
  255.                 DisplayCreateHelpMessage
  256.                 WScript.Quit(ERR_OK)
  257.             End If
  258.  
  259.             aArgs = oScriptHelper.GetSwitch(arg)
  260.  
  261.             strVPath = aArgs(0)
  262.             strAlias = aArgs(1)
  263.             strRoot = aArgs(2)
  264.  
  265.         Case "delete"
  266.             If (intOperation <> 0) Then
  267.                 WScript.Echo L_OnlyOneOper_ErrorMessage
  268.                 WScript.Echo L_SeeHelp_Message
  269.                 WScript.Quit(ERR_GENERAL_FAILURE)
  270.             End If
  271.         
  272.             intOperation = OPER_DELETE
  273.  
  274.             If oScriptHelper.IsHelpRequested(arg) Then
  275.                 DisplayDeleteHelpMessage
  276.                 WScript.Quit(ERR_OK)
  277.             End If
  278.  
  279.             strPath = oScriptHelper.GetSwitch(arg)
  280.  
  281.         Case "query"
  282.             If (intOperation <> 0) Then
  283.                 WScript.Echo L_OnlyOneOper_ErrorMessage
  284.                 WScript.Echo L_SeeHelp_Message
  285.                 WScript.Quit(ERR_GENERAL_FAILURE)
  286.             End If
  287.         
  288.             intOperation = OPER_QUERY
  289.  
  290.             If oScriptHelper.IsHelpRequested(arg) Then
  291.                 DisplayQueryHelpMessage
  292.                 WScript.Quit(ERR_OK)
  293.             End If
  294.  
  295.             strPath = oScriptHelper.GetSwitch(arg)
  296.     End Select
  297. Next
  298.     
  299. ' Check Parameters
  300. If (intOperation = 0) Then
  301.     WScript.Echo L_OperationRequired_ErrorMessage
  302.     WScript.Echo L_SeeHelp_Message
  303.     WScript.Quit(ERR_GENERAL_FAILURE)
  304. End If
  305.  
  306. ' Check if /p is specified but /u isn't. In this case, we should bail out with an error
  307. If oScriptHelper.Switches.Exists("password") And Not oScriptHelper.Switches.Exists("user") Then
  308.     WScript.Echo L_PassWithoutUser_ErrorMessage
  309.     WScript.Quit(ERR_GENERAL_FAILURE)
  310. End If
  311.  
  312. ' Check if /u is specified but /p isn't. In this case, we should ask for a password
  313. If oScriptHelper.Switches.Exists("user") And Not oScriptHelper.Switches.Exists("password") Then
  314.     strPassword = oCmdLib.GetPassword
  315. End If
  316.  
  317. ' Initializes authentication with remote machine
  318. intResult = oScriptHelper.InitAuthentication(strServer, strUser, strPassword)
  319. If intResult <> 0 Then
  320.     WScript.Quit(intResult)
  321. End If
  322.  
  323. ' Choose operation
  324. Select Case intOperation
  325.     Case OPER_CREATE
  326.         intResult = CreateWebVDir(strVPath, strAlias, strRoot)
  327.         
  328.     Case OPER_DELETE
  329.         intResult = DeleteWebVDir(strPath)
  330.  
  331.     Case OPER_QUERY
  332.         intResult = QueryWebVDir(strPath)
  333. End Select
  334.  
  335. ' Return value to command processor
  336. WScript.Quit(intResult)
  337.  
  338. '''''''''''''''''''''''''
  339. ' End Of Main Block
  340. '''''''''''''''''''''
  341.  
  342. '''''''''''''''''''''''''''
  343. ' ParseSitePath
  344. '''''''''''''''''''''''''''
  345. Function ParseSitePath(strSitePath)
  346.     Dim iFirstSlash, iSecondSlash, iIndex
  347.     Dim strSite, strPath
  348.     Dim aPath, aWebSites
  349.     
  350.     On Error Resume Next
  351.     
  352.     ' Replace any existing back-slashes with forward-slashes
  353.     strSitePath = Replace(strSitePath, "\", "/")
  354.     
  355.     aPath = Split(strSitePath, "/", -1)
  356.  
  357.     ' Fills strPath
  358.     If (UCase(aPath(0)) = "W3SVC") Then
  359.         ' First argument is a metabase path
  360.         If (UBound(aPath) < 1) Then
  361.             WScript.Echo L_InvalidPath_ErrorMessage
  362.             WScript.Quit(ERR_GENERAL_FAILURE)
  363.         End If
  364.         
  365.         ' Second array element must be a number (site ID)
  366.         If Not IsNumeric(aPath(1)) Then
  367.             WScript.Echo L_InvalidPath_ErrorMessage
  368.             WScript.Quit(ERR_GENERAL_FAILURE)
  369.         End If
  370.         
  371.         ' Second element of aPath should be the site number so ...
  372.         strPath = "W3SVC/" & aPath(1)
  373.         
  374.         ' Call FindWebSite to make sure web site exists
  375.         aWebSites = oScriptHelper.FindSite("Web", Array(strPath))
  376.         If IsArray(aWebSites) Then
  377.             If UBound(aWebSites) = -1 Then
  378.                 oCmdLib.vbPrintf L_SiteNotFound_ErrorMessage, Array(strPath)
  379.                 ParseSitePath = Empty
  380.                 Exit Function
  381.             End If
  382.         End If
  383.  
  384.         strPath = strPath & "/ROOT"
  385.         strSitePath = strPath
  386.         
  387.         ' Check for ROOT string and grab the rest for strPath
  388.         iIndex = 1
  389.         If (UBound(aPath) > 1) Then
  390.             If (UCase(aPath(2)) = "ROOT") Then
  391.                 iIndex = 2
  392.             End If
  393.         End If
  394.         
  395.     Else
  396.         ' First argument is a site name (server comment property)
  397.         ' Call FindWebSite to resolve site name to metabase path
  398.         aWebSites = oScriptHelper.FindSite("Web", Array(aPath(0)))
  399.         If IsArray(aWebSites) Then
  400.             If UBound(aWebSites) = -1 Then
  401.                 oCmdLib.vbPrintf L_SiteNotFound_ErrorMessage, Array(aPath(0))
  402.                 ParseSitePath = Empty
  403.                 Exit Function
  404.             Else
  405.                 strPath = aWebSites(0)
  406.             End If
  407.         Else
  408.             ' Got duplicate sites. We should quit.
  409.             ParseSitePath = Empty
  410.             Exit Function
  411.         End If
  412.         
  413.         strPath = strPath & "/ROOT"
  414.  
  415.         strSitePath = aPath(0) & "/ROOT"
  416.  
  417.         ' Check for ROOT string and grab the rest for strPath
  418.         iIndex = 0
  419.         If (UBound(aPath) > 0) Then
  420.             If (UCase(aPath(1)) = "ROOT") Then
  421.                 iIndex = 1
  422.             End If
  423.         End If
  424.  
  425.     End If
  426.  
  427.     ' Build strPath    
  428.     iIndex = iIndex + 1
  429.     Do While iIndex <= UBound(aPath)
  430.         If (aPath(iIndex) = "") Then
  431.             Exit Do
  432.         End If
  433.         
  434.         strPath = strPath & "/" & aPath(iIndex)
  435.         strSitePath = strSitePath & "/" & aPath(iIndex)
  436.  
  437.         iIndex = iIndex + 1
  438.     Loop
  439.     
  440.     ParseSitePath = strPath
  441. End Function
  442.  
  443.  
  444. '''''''''''''''''''''''''''
  445. ' DisplayHelpMessage
  446. '''''''''''''''''''''''''''
  447. Sub DisplayHelpMessage()
  448.     WScript.Echo L_Help_HELP_General01_Text
  449.     WScript.Echo
  450.     WScript.Echo L_Help_HELP_General02_Text
  451.     WScript.Echo L_Help_HELP_General03_Text
  452.     WScript.Echo 
  453.     WScript.Echo L_Help_HELP_General04_Text
  454.     WScript.Echo 
  455.     WScript.Echo L_Help_HELP_General06_Text
  456.     WScript.Echo L_Help_HELP_General07_Text
  457.     WScript.Echo L_Help_HELP_General08_Text
  458.     WScript.Echo L_Help_HELP_General09_Text
  459.     WScript.Echo L_Help_HELP_General10_Text
  460.     WScript.Echo L_Help_HELP_General11_Text
  461.     WScript.Echo L_Help_HELP_General12_Text
  462.     WScript.Echo L_Help_HELP_General13_Text
  463.     WScript.Echo L_Help_HELP_General14_Text
  464.     WScript.Echo L_Help_HELP_General15_Text
  465.     WScript.Echo L_Help_HELP_General16_Text
  466.     WScript.Echo 
  467.     WScript.Echo L_Help_HELP_General17_Text
  468.     WScript.Echo 
  469.     WScript.Echo L_Help_HELP_General18_Text
  470.     WScript.Echo L_Help_HELP_General19_Text
  471.     WScript.Echo L_Help_HELP_General20_Text
  472. End Sub
  473.  
  474. Sub DisplayDeleteHelpMessage()
  475.     WScript.Echo L_Help_HELP_Delete01_Text
  476.     WScript.Echo L_Help_HELP_Delete01p1_Text
  477.     WScript.Echo 
  478.     WScript.Echo L_Help_HELP_Delete02_Text
  479.     WScript.Echo L_Help_HELP_Delete02p1_Text
  480.     WScript.Echo 
  481.     WScript.Echo L_Help_HELP_Common03_Text
  482.     WScript.Echo 
  483.     WScript.Echo L_Help_HELP_General06_Text
  484.     WScript.Echo L_Help_HELP_General07_Text
  485.     WScript.Echo L_Help_HELP_General08_Text
  486.     WScript.Echo L_Help_HELP_General09_Text
  487.     WScript.Echo L_Help_HELP_General10_Text
  488.     WScript.Echo L_Help_HELP_Common09_Text
  489.     WScript.Echo L_Help_HELP_Common09p1_Text
  490.     WScript.Echo L_Help_HELP_Common09p2_Text
  491.     WScript.Echo L_Help_HELP_Common10_Text
  492.     WScript.Echo L_Help_HELP_Common10p1_Text
  493.     WScript.Echo L_Help_HELP_Common10p2_Text
  494.     WScript.Echo 
  495.     WScript.Echo L_Help_HELP_Common11_Text
  496.     WScript.Echo 
  497.     WScript.Echo L_Help_HELP_Delete11_Text
  498.     WScript.Echo L_Help_HELP_Delete12_Text
  499.     WScript.Echo L_Help_HELP_Delete13_Text
  500. End Sub
  501.  
  502. Sub DisplayCreateHelpMessage()
  503.     WScript.Echo L_Help_HELP_Create01_Text
  504.     WScript.Echo L_Help_HELP_Create01p1_Text
  505.     WScript.Echo
  506.     WScript.Echo L_Help_HELP_Create02_Text
  507.     WScript.Echo L_Help_HELP_Create02p1_Text
  508.     WScript.Echo
  509.     WScript.Echo L_Help_HELP_Common03_Text
  510.     WScript.Echo
  511.     WScript.Echo L_Help_HELP_General06_Text
  512.     WScript.Echo L_Help_HELP_General07_Text
  513.     WScript.Echo L_Help_HELP_General08_Text
  514.     WScript.Echo L_Help_HELP_General09_Text
  515.     WScript.Echo L_Help_HELP_General10_Text
  516.     WScript.Echo L_Help_HELP_Common09_Text
  517.     WScript.Echo L_Help_HELP_Common09p1_Text
  518.     WScript.Echo L_Help_HELP_Common09p2_Text
  519.     WScript.Echo L_Help_HELP_Common10_Text
  520.     WScript.Echo L_Help_HELP_Common10p1_Text
  521.     WScript.Echo L_Help_HELP_Common10p2_Text
  522.     WScript.Echo L_Help_HELP_Create11_Text
  523.     WScript.Echo L_Help_HELP_Create12_Text
  524.     WScript.Echo L_Help_HELP_Create12p1_Text
  525.     WScript.Echo L_Help_HELP_Create12p2_Text
  526.     WScript.Echo
  527.     WScript.Echo L_Help_HELP_Common11_Text
  528.     WScript.Echo
  529.     WScript.Echo L_Help_HELP_Create15_Text
  530.     WScript.Echo L_Help_HELP_Create16_Text
  531.     WScript.Echo L_Help_HELP_Create17_Text
  532.     WScript.Echo L_Help_HELP_Create18_Text
  533.     WScript.Echo L_Help_HELP_Create19_Text
  534. End Sub
  535.  
  536. Sub DisplayQueryHelpMessage()
  537.     WScript.Echo L_Help_HELP_Query01_Text
  538.     WScript.Echo L_Help_HELP_Query01p1_Text
  539.     WScript.Echo
  540.     WScript.Echo L_Help_HELP_Query02_Text
  541.     WScript.Echo L_Help_HELP_Query02p1_Text
  542.     WScript.Echo
  543.     WScript.Echo L_Help_HELP_Common03_Text
  544.     WScript.Echo
  545.     WScript.Echo L_Help_HELP_General06_Text
  546.     WScript.Echo L_Help_HELP_General07_Text
  547.     WScript.Echo L_Help_HELP_General08_Text
  548.     WScript.Echo L_Help_HELP_General09_Text
  549.     WScript.Echo L_Help_HELP_General10_Text
  550.     WScript.Echo L_Help_HELP_Common09_Text
  551.     WScript.Echo L_Help_HELP_Common09p1_Text
  552.     WScript.Echo L_Help_HELP_Common09p2_Text
  553.     WScript.Echo L_Help_HELP_Common10_Text
  554.     WScript.Echo L_Help_HELP_Common10p1_Text
  555.     WScript.Echo L_Help_HELP_Common10p2_Text
  556.     WScript.Echo
  557.     WScript.Echo L_Help_HELP_Common11_Text
  558.     WScript.Echo
  559.     WScript.Echo L_Help_HELP_Query11_Text
  560.     WScript.Echo L_Help_HELP_Query12_Text
  561.     WScript.Echo L_Help_HELP_Query13_Text
  562.     WScript.Echo L_Help_HELP_Query14_Text
  563. End Sub
  564.  
  565. '''''''''''''''''''''''''''
  566. ' DeleteWebVDir
  567. '''''''''''''''''''''''''''
  568. Function DeleteWebVDir(strVPath)
  569.     Dim strPath, ServiceObj
  570.     Dim rootVDirObj, providerObj
  571.     
  572.     On Error Resume Next
  573.     
  574.     oScriptHelper.WMIConnect
  575.     If Err.Number Then
  576.         WScript.Echo L_WMIConnect_ErrorMessage
  577.         oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  578.         ChangeWebSiteStatus = Err.Number
  579.         Exit Function
  580.     End If
  581.  
  582.     Set providerObj = oScriptHelper.ProviderObj
  583.  
  584.     ' Quick check to see if we have permission
  585.     Set ServiceObj = providerObj.Get("IIsWebService='W3SVC'")
  586.     If Err.Number Then
  587.         Select Case Err.Number
  588.             Case &H80070005
  589.                 WScript.Echo L_Admin_ErrorMessage
  590.                 WScript.Echo L_Admin2_ErrorMessage
  591.  
  592.             Case Else
  593.                 WScript.Echo Err.Description
  594.         End Select
  595.         
  596.         DeleteWebVDir = Err.Number
  597.         Exit Function
  598.     End If
  599.  
  600.     strPath = ParseSitePath(strVPath)
  601.     If IsEmpty(strPath) Then
  602.         ' Got problems parsing the path
  603.         WScript.Echo L_SeeDeleteHelp_Message
  604.         DeleteWebVDir = ERR_GENERAL_FAILURE
  605.         Exit Function
  606.     End If
  607.     
  608.     ' Don't delete ROOT Vdir
  609.     If UCase(Right(strPath, 5)) = "/ROOT" Then
  610.         WScript.Echo L_CannotDelRoot_ErrorMessage
  611.         WScript.Echo L_CannotDelRoot2_ErrorMessage
  612.         DeleteWebVDir = ERR_GENERAL_FAILURE
  613.         Exit Function
  614.     End If
  615.     
  616.     ' Check vdir existance
  617.     Set rootVDirObj = providerObj.Get("IIsWebVirtualDir='" & strPath & "'")
  618.     If Err.Number Then
  619.         Select Case Err.Number
  620.             Case &H80041002
  621.                 WScript.Echo L_VDirDoesntExist_ErrorMessage
  622.                 oCmdLib.vbPrintf L_VDirDoesntExist2_ErrorMessage, Array(strVPath)
  623.         
  624.             Case &H8004103A
  625.                 WScript.Echo L_KeyIsntVDir_ErrorMessage
  626.                 
  627.             Case Else
  628.                 oCmdLib.vbPrintf L_VDirExists1_ErrorMessage, Array(strVPath)
  629.                 WScript.Echo L_CannotGetVDir_ErrorMessage
  630.                 WScript.Echo L_CannotGetVDir2_ErrorMessage
  631.                 WScript.Echo L_CannotGetVDir3_ErrorMessage
  632.         End Select
  633.         
  634.         DeleteWebVDir = Err.Number
  635.         Exit Function
  636.     End If
  637.     
  638.        ' First delete application recursively in this vdir
  639.     rootVDirObj.AppDelete(True)
  640.     If Err.Number Then
  641.         WScript.Echo L_AppRecursiveDel_ErrorMessage
  642.         oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  643.         DeleteWebVDir = Err.Number
  644.         Exit Function
  645.     End If
  646.         
  647.     rootVDirObj.Delete_()
  648.     If Err.Number Then
  649.         WScript.Echo L_VDirDel_ErrorMessage
  650.         oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  651.         DeleteWebVDir = Err.Number
  652.         Exit Function
  653.     End If
  654.  
  655.        oCmdLib.vbPrintf L_WebDir_Message, Array(strVPath)
  656.     
  657.     DeleteWebVDir = ERR_OK
  658. End Function
  659.  
  660.  
  661. '''''''''''''''''''''''''''
  662. ' CreateWebVDir
  663. '''''''''''''''''''''''''''
  664. Function CreateWebVDir(strVPath, strAlias, strRoot)
  665.     Dim strPath, strStatus, strNewVdir, strRootVDir
  666.     Dim vdirClassObj, serverObj, vdirObj, providerObj
  667.     Dim intResult, ServiceObj
  668.  
  669.     Const APP_POOLED = 2
  670.     
  671.     On Error Resume Next
  672.     
  673.     ' Parse Alias for correctness
  674.     If InStr(strAlias, "/") <> 0 Or InStr(strAlias, "\") <> 0 Then
  675.         WScript.Echo L_InvalidAlias_ErrorMessage
  676.         WScript.Echo L_SeeCreateHelp_Message
  677.         CreateWebVDir = ERR_GENERAL_FAILURE
  678.         Exit Function
  679.     End If
  680.  
  681.     oScriptHelper.WMIConnect
  682.     If Err.Number Then
  683.         WScript.Echo L_WMIConnect_ErrorMessage
  684.         oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  685.         CreateWebVDir = Err.Number
  686.         Exit Function
  687.     End If
  688.  
  689.     Set providerObj = oScriptHelper.ProviderObj
  690.     
  691.     ' Quick check to see if we have permission
  692.     Set ServiceObj = providerObj.Get("IIsWebService='W3SVC'")
  693.     If Err.Number Then
  694.         Select Case Err.Number
  695.             Case &H80070005
  696.                 WScript.Echo L_Admin_ErrorMessage
  697.                 WScript.Echo L_Admin2_ErrorMessage
  698.  
  699.             Case Else
  700.                 WScript.Echo Err.Description
  701.         End Select
  702.         
  703.         CreateWebVDir = Err.Number
  704.         Exit Function
  705.     End If
  706.  
  707.     ' Extract options from array to the correspondent variables
  708.     strPath = ParseSitePath(strVPath)
  709.     If IsEmpty(strPath) Then
  710.         ' Got problems parsing the path
  711.         WScript.Echo L_SeeCreateHelp_Message
  712.         CreateWebVDir = ERR_GENERAL_FAILURE
  713.         Exit Function
  714.     End If
  715.  
  716.     ' Build new vdir name
  717.     strNewVdir = strPath & "/" & strAlias
  718.     
  719.     ' Check if vdir already exists
  720.     Set vdirObj = providerObj.Get("IIsWebDirectorySetting='" & strNewVdir & "'")
  721.     If Err.Number = 0 Then
  722.         oCmdLib.vbPrintf L_VDirExists2_ErrorMessage, Array(strNewVdir)
  723.         CreateWebVDir = ERR_GENERAL_FAILURE
  724.         Exit Function
  725.     End If
  726.     Err.Clear
  727.  
  728.     Set vdirObj = providerObj.Get("IIsWebVirtualDirSetting='" & strNewVdir & "'")
  729.     If Err.Number = 0 Then
  730.         oCmdLib.vbPrintf L_VDirExists2_ErrorMessage, Array(strNewVdir)
  731.         CreateWebVDir = ERR_GENERAL_FAILURE
  732.         Exit Function
  733.     End If
  734.     Err.Clear
  735.     
  736.     ' Create physical directory
  737.     oScriptHelper.CreateFSDir strRoot
  738.     If Err.Number Then
  739.         Select Case Err.Number
  740.             Case &H8007000C
  741.                 WScript.Echo L_DirFormat_ErrorMessage
  742.                 WScript.Echo L_DirFormat2_ErrorMessage
  743.                 WScript.Echo L_SeeCreateHelp_Message
  744.             
  745.             Case &H8007000F
  746.                 WScript.Echo L_MapDrive_ErrorMessage
  747.     
  748.             Case Else
  749.                 WScript.Echo L_CannotCreateDir_ErrorMessage
  750.                 oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  751.         End Select
  752.  
  753.         CreateWebVDir = Err.Number
  754.         Exit Function
  755.     End If
  756.  
  757.     ' Check if we have a contiguous name space in the metabase and file system
  758.     oScriptHelper.BuildNameSpace strPath
  759.     If Err.Number Then
  760.         Select Case Err.Number
  761.             Case &H80070003
  762.                 WScript.Echo L_WrongVDirPath_ErrorMessage
  763.                 WScript.Echo L_WrongVDirPath2_ErrorMessage
  764.             
  765.             Case Else
  766.                 WScript.Echo L_CannotBuildNameSpace_ErrorMessage
  767.                 WScript.Echo L_CannotBuildNameSpace2_ErrorMessage
  768.                 oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  769.         End Select
  770.  
  771.         CreateWebVDir = Err.Number
  772.         Exit Function
  773.     End If
  774.  
  775.     ' Remove trailing slash (if present)
  776.     If (Right(strRoot, 1) = "\") Then
  777.         strRoot = Left(strRoot, Len(strRoot) - 1)
  778.     End If
  779.  
  780.     ' Create new web virtual directory
  781.     Set vdirClassObj = providerObj.Get("IIsWebVirtualDirSetting")
  782.     Set vdirObj = vdirClassObj.SpawnInstance_()
  783.     vdirObj.Name = strNewVdir
  784.     vdirObj.Path = strRoot
  785.  
  786.     ' Set web virtual directory properties
  787.     vdirObj.AuthFlags = 5 ' AuthNTLM + AuthAnonymous
  788.     vdirObj.EnableDefaultDoc = True
  789.     vdirObj.DirBrowseFlags = &H4000003E ' date, time, size, extension, longdate
  790.     vdirObj.AccessFlags = 513 ' read, script
  791.     vdirObj.Put_()
  792.  
  793.     ' Create Pooled-proc application on ROOT WebVDir
  794.     Set vdirObj = providerObj.Get("IIsWebVirtualDir='" & strNewVdir & "'")
  795.     vdirObj.AppCreate2(APP_POOLED)
  796.     If Err.Number Then
  797.         WScript.Echo L_AppCreate_ErrorMessage
  798.         WScript.Echo L_AppCreate2_ErrorMessage
  799.         oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  800.         intResult = ERR_GENERAL_FAILURE
  801.     End If
  802.     
  803.     ' Update AppFriendlyName property
  804.     Set vdirObj = providerObj.Get("IIsWebVirtualDirSetting='" & strNewVdir & "'")
  805.     vdirObj.AppFriendlyName = strAlias
  806.     vdirObj.Put_()
  807.     
  808.     ' Remove trailing slash (if present)
  809.     If (Right(strVPath, 1) = "/") Then
  810.         strVPath = Left(strVPath, Len(strVPath) - 1)
  811.     End If
  812.     
  813.     If (strServer = ".") Then 
  814.         strServer = oScriptHelper.GetEnvironmentVar("%COMPUTERNAME%")
  815.     End If
  816.  
  817.     ' Post summary
  818.     WScript.Echo L_Server_Message & Space(14 - Len(L_Server_Message)) & "= " & UCase(strServer)
  819.     WScript.Echo L_VPath_Message & Space(14 - Len(L_VPath_Message)) & "= " & strVPath & "/" & strAlias
  820.     WScript.Echo L_Root_Message & Space(14 - Len(L_Root_Message)) & "= " & strRoot
  821.     WScript.Echo L_MetabasePath_Message & Space(14 - Len(L_MetabasePath_Message)) & "= " & strNewVdir
  822.     
  823.     CreateWebVDir = intResult
  824. End Function
  825.  
  826.  
  827. '''''''''''''''''''''''''''
  828. ' Helper Functions
  829. '''''''''''''''''''''''''''
  830.  
  831. '''''''''''''''''''''''''''
  832. ' QueryWebVDir
  833. '''''''''''''''''''''''''''
  834. Function QueryWebVDir(strVDir)
  835.     Dim Servers, Server, strQuery
  836.     Dim bFirstIteration
  837.     Dim vdirObj, providerObj
  838.     Dim strServer, strPath, strVDirName
  839.     Dim firstLen, ServiceObj
  840.     
  841.     On Error Resume Next
  842.  
  843.     oScriptHelper.WMIConnect
  844.     If Err.Number Then
  845.         WScript.Echo L_WMIConnect_ErrorMessage
  846.         oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  847.         QueryWebVDir = Err.Number
  848.         Exit Function
  849.     End If
  850.  
  851.     Set providerObj = oScriptHelper.ProviderObj
  852.  
  853.     ' Quick check to see if we have permission
  854.     Set ServiceObj = providerObj.Get("IIsWebService='W3SVC'")
  855.     If Err.Number Then
  856.         Select Case Err.Number
  857.             Case &H80070005
  858.                 WScript.Echo L_Admin_ErrorMessage
  859.                 WScript.Echo L_Admin2_ErrorMessage
  860.  
  861.             Case Else
  862.                 WScript.Echo Err.Description
  863.         End Select
  864.         
  865.         QueryWebVDir = Err.Number
  866.         Exit Function
  867.     End If
  868.  
  869.     strPath = ParseSitePath(strVDir)
  870.     If IsEmpty(strPath) Then
  871.         ' Got problems parsing the path
  872.         WScript.Echo L_SeeQueryHelp_Message
  873.         QueryWebVDir = ERR_GENERAL_FAILURE
  874.         Exit Function
  875.     End If
  876.  
  877.     ' Semi-sync query. (flags = ForwardOnly Or ReturnImediately = &H30)
  878.     strQuery = "ASSOCIATORS OF {IIsDirectory=""" & strPath & """} WHERE ResultClass = IIsWebVirtualDir " & _
  879.         "ResultRole = PartComponent"
  880.     Set Servers = providerObj.ExecQuery(strQuery, , &H30)
  881.     If (Err.Number <> 0) Then
  882.         WScript.Echo L_Query_ErrorMessage
  883.         oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  884.         QueryWebVDir = Err.Number
  885.         Exit Function
  886.     End If
  887.  
  888.     bFirstIteration = True
  889.     For Each Server in Servers
  890.         
  891.         If Server.Name = "" Then
  892.             WScript.Echo L_CannotGetVDir_ErrorMessage
  893.             WScript.Echo L_CannotGetVDir2_ErrorMessage
  894.             WScript.Echo L_CannotGetVDir3_ErrorMessage
  895.             Exit Function
  896.         End If
  897.  
  898.         If bFirstIteration Then
  899.             WScript.Echo L_AliasName_Text & Space(35 - Len(L_AliasName_Text)) & L_Path_Text
  900.             WScript.Echo "=============================================================================="
  901.         End If
  902.  
  903.         Err.Clear
  904.         Set vdirObj = providerObj.get("IIsWebVirtualDirSetting=""" & Server.Name & """")
  905.         If (Err.Number <> 0) Then
  906.             WScript.Echo L_GetSetting_ErrorMessage
  907.             oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  908.             QueryWebVDir = Err.Number
  909.             Exit Function
  910.         End If
  911.         
  912.         ' If this is the first binding list, print server comment and server name
  913.         strVDirName = Replace(vdirObj.Name, strPath, "") ', , , vbTextCompare)
  914.         firstLen = 35 - Len(strVDirName)
  915.         If (firstLen < 1) Then
  916.             firstLen = 1
  917.         End If
  918.  
  919.         WScript.Echo strVDirName & Space(firstLen) & vdirObj.Path
  920.         
  921.         bFirstIteration = False
  922.     Next
  923.  
  924.     If bFirstIteration Then
  925.         WScript.Echo L_VDirsNotFound_ErrorMessage
  926.     End If
  927.  
  928.     QueryWebVDir = ERR_OK
  929. End Function
  930.